package com.xyy.saas.payment.manage.cores.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

public enum BusinessTypeEnum {

    /**
     * EC
     */
    EC("ec", "EC"),
    /**
     * 一块钱
     */
    YIKUAIQIAN("yikuaiqian", "一块钱"),
    /**
     * SAAS
     */
    SAAS("saas", "SAAS"),
    /**
     * INS
     */
    INS("ins", "保险"),
    /**
     * HEYE
     */
    HEYE("heye", "荷叶");

    private String type;
    private String desc;

    private static Map<String,BusinessTypeEnum> code2Enum;

    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(BusinessTypeEnum::getType, UnaryOperator.identity()));
    }

    public static BusinessTypeEnum getEnum(String type){
        return code2Enum.get(type);
    }

    BusinessTypeEnum(String type, String desc){
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static boolean contains(String type) {
        try {
            return BusinessTypeEnum.valueOf(type.toUpperCase()).type.equals(type);
        } catch (Exception e) {
        }
        return false;
    }
}
